package com.sofwin.controller;

import com.sofwin.R;
import com.sofwin.pojo.SysResource;
import com.sofwin.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @packageName: com.sofwin.controller
 * @user: andyliu
 * @date: 2023/5/17 17:13
 * @email 115176513@qq.com
 * @description: TODO
 */
@Controller
@RequestMapping("resource")
public class ResourceController {
    @Autowired
    private ResourceService resourceService;

    @GetMapping
    @ResponseBody
    public R resourceData(Integer roleId){
        // 查询所有资源，并将该角色拥有的资源的checked属性改为true
        List<SysResource> resources = resourceService.queryResourcesByRoleId(roleId);
        return R.success(resources);
    }
    @GetMapping("list")
    public String list(){
        return "resource/list";
    }
    @GetMapping("data")
    @ResponseBody
    public R data(){
        List<SysResource> resources = resourceService.queryResources();
        return R.success(resources);

    }

}
